<extend name="Public/base" />

<block name="style">

</block>

<block name="body">
	<!-- 弹窗插件 -->
	<include file="Public:artdialog" />

	<div class="row">
		<div class="col-md-12">
			<div class="block-web">
				<!-- 商品列表 -->
				<form action="{:U('groupList')}" method="post" id="SearchFrom" class="vform">
					<div class="bgmain">
						<div class="header">
							<div class="actions_diy">
								<!-- <a href="javascript:;" onclick="_es_openDilogLarge('{:U('add_red')}','添加红冲充值')" class="btn btn-default btn-primary"> -->
								<a href="javascript:;" onclick="window.location='{:U('addGroup',array('blongtype'=>'Group'))}'" class="btn btn-default btn-primary">
									<i class="fa fa-plus"></i>添加拼团包
								</a>
							</div>
							<div class="actions_diy" style="margin-right:10px;">
								<!-- <a href="javascript:;" onclick="_es_openDilogLarge('{:U('add_red')}','添加红冲充值')" class="btn btn-default btn-primary"> -->
								<a href="javascript:;" onclick="window.location='{:U('addGroup',array('blongtype'=>'presell'))}'" class="btn btn-default btn-primary">
									<i class="fa fa-plus"></i>添加预售包
								</a>
							</div>
							<h3 class="content-header">拼团包管理</h3>
						</div>

						<div class="block-web" style="margin: 0;padding:10px 20px 0px 0px;">
							<div class="porlets-content">
								<div class="row" style="margin-left:-45px;">
									<div class="col-md-12" style="padding-left:0px;">
										<div class="search_pannl_div">
											<table class="search_table table-condensed">
												<tbody>
												<tr>
													<td class="single-col">
														<label>时间(开始)</label>
														<input name="start_time" readonly="readonly" class="laydate-icon" style="width: 160px;padding: 0px;height: 20px;" type="text" id="start_time" size="15" value="{:I('param.start_time')}">
														&nbsp;&nbsp;
														时间(结束)
														<input name="end_time" readonly="readonly" class="laydate-icon" style="width: 160px;padding: 0px;height: 20px;" type="text" id="end_time" size="15" value="{:I('param.end_time')}">

														<label>是否满员：</label>
														<input type="radio"  name="isaccord" value="1" <?php if(I("param.isaccord"))echo "checked";?>/>
														<span class="custom-radio"></span> 满员
														<input type="radio"  name="isaccord" value="0" <?php if(I("param.isaccord") =="0") echo "checked";?>/>
														<span class="custom-radio"></span> 不满员
														<label>是否审核：</label>
														<input type="radio"  name="isactive" value="1" <?php if(I("param.isactive"))echo "checked";?>/>
														<span class="custom-radio"></span> 已审核
														<input type="radio"  name="isactive" value="0" <?php if(I("param.isactive") =="0") echo "checked";?>/>
														<span class="custom-radio"></span> 未审核
														<label>包类型：</label>
														<select name="blongtype">
															<option value="">-全部-</option>
															<option value="Group" <?php if(I("param.blongtype") == 'Group')echo "selected";?>>拼团包</option>
															<option value="presell" <?php if(I("param.blongtype") == 'presell')echo "selected";?>>预售包</option>
														</select>
														<label>关键词：</label><input style="width:210px;" type="text" id="keywords" name="keywords" placeholder="输入团包名称查找" value="{:I('param.keywords')}">
														<button type="button" class="btn btn-success" formtarget="SearchFrom" id="searchBtn" onclick="goSearch()"><i class="fa fa-search"></i> 搜索</button>
														<button type="button" class="btn btn-default" onclick="$('input').val(['']);$('select').val('');goSearch();"> 查看所有</button>
													</td>
												</tr>
												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>

					<div id="load_tb_divs" style="padding:10px 0px 30px ;">
						<table class="table table-striped goods_list_table   table-bordered table-condensed">
							<thead>
							<tr>
								<th class="opth40"><label>
                                <input type="checkbox"  id="all" value="" >
                                 </label></th>
								<th class="opth40">序号</th>
								<th class="opth40">团包名称</th>
								<th class="opth40">团包类型</th>
								<th class="opth40">组团数量</th>
								<th class="opth70">零售团购总价格</th>
								<th class="opth70">会员团购总价格</th>
								<th class="opth70">VIP团购总价格</th>
								<th class="opth70">最小购买数量</th>
								<th class="opth70">最大购买数量</th>
								<th class="opth40">开始时间</th>
								<th class="opth40">结束时间</th>
								<th class="opth50">是否满员</th>
								<th class="opth50">团包发起人</th>
								<th class="opth40">操作员</th>
								<th class="opth40">修改时间</th>
								<th class="opth100">操作</th>

							</tr>
							</thead>
							<tbody id="tbodylist">
							<!--  <volist name="results['lists']" id="lists">
                                 <tr>
                                     <td>{$lists['id']}</td>
                                     <td>{$lists['title']}</td>
                                     <td>{$lists['content']|default='-'}</td>
                                     <td>{$lists['keywords']|default='-'}</td>
                                     <td>{$lists['admin_user']|default='-'}</td>
                                     <td>{$lists['createtime']|default='-'}</td>
                                     <td>
                                     <if condition="$lists.status eq 1">
                                     开启
                                     <else />
                                     隐藏
                                     </if>
                                     </td>
                                     <td>hhhhh</td>

            </tr>
        </volist> -->
		 <volist name="results" id="lists">
            <tr>
			<td>
			    <label class="checkbox">
            	<input type="checkbox" name="check" value="{$lists['packageid']}"/>
				</label></td>
            	<td>{$key+1}</td>
            	<td>{$lists['packagename']}
				</td>
				<if condition="$lists['blongtype'] eq 'Group'">
				<td>拼团包</td>
				<else />
				<td>预售包</td>
				</if>
				<td>{$lists['total']|default='-'}</td>
				<td>{$lists['sprice']}</td>
				<td>{$lists['uprice']}</td>
				<td>{$lists['vprice']}</td>
				<td>{$lists['minnumber']}</td>
				<td>{$lists['maxnumber']}</td>
            	<td>{$lists['starttime']|default='-'}</td>
            	<td>{$lists['endtime']|default='-'}</td>
                <td>
				<if condition="$lists.isaccord eq 1">
				满员
				<else />
				不满员
				</if>
				</td>
				<td>{$lists['username']|default='-'}</td>
				<td>{$lists['user_name']|default='-'}</td>
				<td>{$lists['addtime']|default='-'}</td>
                <td>
				<!--<a class="btn btn-white btn-sm" id="add_edit_id" onclick="_es_openDilog90('{:U('goodslist',array('special_id'=>$lists['id']))}','专题-{$lists['title']}-添加商品');">添加商品</a>
				 <if condition="$lists['url'] neq null">
				<a class="btn btn-white btn-sm" onclick="javascript:void(0);" id="add_edit_id" value="添加商品">添加商品</a>
				<else />
				<a class="btn btn-white btn-sm" onclick="addgoods(this,{$lists.id})" url="{:U('goodslist',array('special_id'=>$lists['id']))}" id="add_edit_id" value="添加商品">添加商品</a>
				</if> 
				&nbsp;                                                                                                                                                                                       
				<a class="btn btn-white btn-sm" onclick="_es_openDilog90('{:U('showgoods',array('special_id'=>$lists['id']))}','专题-{$lists['title']}-商品详情');">查看商品</a>
				&nbsp;-->
 				<if condition="$lists.usertype eq 0">
 				<if condition="$lists.isactive eq 1">
				<a href="javascript:void(0);" class="btn btn-sm btn-danger" onclick="doExamine('{$lists.packageid}','del')">取消审核</a>
				<else />
				<a href="javascript:void(0);" class="btn btn-sm btn-white" onclick="doExamine('{$lists.packageid}','do')">审核</a>
				</if>
				</if>
                <a href="javascript:;" class="btn btn-sm btn-primary" onclick="_es_openDilogLarge('{:U('order_info',array('packageid'=>$lists['packageid']))}','包订单')">包订单</a>
				&nbsp;
				<if condition="$lists.is_complete neq 1">
				<a href="javascript:void(0);" url="{:U('edit',array('id'=>$lists['packageid'],'blongtype'=>$lists['blongtype'],'edit'=>0))}" onclick="check_edit('{$lists.packageid}','edit',this)" class="btn btn-sm btn-primary">编辑</a>
				&nbsp;
				
				   <a href="javascript:;" class="btn btn-sm btn-primary" onclick="_es_openDilogLarge('{:U('add_promoter',array('packageid'=>$lists['packageid']))}','团购/预售订单查看')" >添加发起人</a>
				&nbsp;
				</if>
				<a href="{:U('edit',array('id'=>$lists['packageid'],'blongtype'=>$lists['blongtype'],'type'=>'group'))}"  class="btn btn-sm btn-primary">查看</a>
				&nbsp;
				<a href="javascript:void(0);" class="btn btn-sm btn-danger" onclick="check('{$lists.packageid}','del','')">删除</a>
				<if condition="$lists.is_complete eq 1">
				  <font color="red">团购完成</font>
				<else />
				<a href="javascript:void(0);" class="btn btn-sm btn-primary" onclick="check('{$lists.packageid}','complete','')">完成团购</a>
				</if>
				
				</td>

                                 </tr>
                             </volist> 
							<empty name="results">
								<tr>
									<td style="padding:30px;text-align:center;" colspan="17">
										暂无相关记录
									</td>
								</tr>
								<else />
								<tr>
									<td colspan="17">
										<a href="javascript:void(0);" class="btn btn-sm btn-danger" id="delete"/>批量删除</a>
										<a href="javascript:void(0);" class="btn btn-sm btn-danger" id="examine"/>批量取消审核</a>
										<span class="btn btn-sm btn-white">已添加的包数：{$count}</span>
										<div class="page_list_ops dataTables_paginate paging_bootstrap pagination">
											{$show}
										</div>
									</td>
								</tr>
							</empty>

							</tbody>
						</table>
					</div>
					<input type="hidden" name="listrows" id="listrows" value="{:I('param.listrows')}">
					<input type="hidden" name="_page" id="_page" value="">
				</form>


			</div><!--/porlets-content-->
		</div><!--/block-web-->
	</div><!--/col-md-12-->

</block>

<block name="script">
	<script type="text/javascript" src="/plugins/laydate/laydate.dev.js"></script>
	<script type="text/javascript">
		laydate({
			elem: '#start_time',
			festival: true, //显示节日
			istime: true,
			format: 'YYYY-MM-DD hh:mm:ss',
		});
		laydate({
			elem: '#end_time',
			festival: true, //显示节日
			istime: true,
			format: 'YYYY-MM-DD hh:mm:ss',
		});
		//单个删除数据
		function deletes(id){
			if(confirm('确定要删除这些吗？'))
			{
					 $.post("{:U('delGroup')}",{id:id},function(data){
						   if(data.status == 1)
						   {
							  
							   window.location.href="{:U('groupList')}";
						   }
						   else if(data.status == 0)
						   {
							   alert(data.message);
						   }
					 });
			 }
		}

 $("#all").click(function (){
       var flg= $(this).is(":checked");
       $("input[type='checkbox']").prop("checked",flg);
    });
					//是否完成
		function iscomplete(id){
		    if(confirm('确定要完成团购吗？'))
			{
					 $.post("{:U('iscomplete')}",{id:id},function(data){
						   if(data.status == 1)
						   {
							  
							   window.location.href="{:U('groupList')}";

						   }
						   else if(data.status == 0)
						   {
							   alert(data.message);
						   }
					 });
			 }
		}
<!-- 			 //批量删除数据
	//	$("#delete").click(function(){
		//		  var aa = $("input[name='check']");
		//			var ids = new Array();
			//		var j=0;
		//			for (var i = 0; i < aa.length; i++) {
			//			if (aa[i].checked) {
			//				ids[j] = aa[i].value;
			//				j++;
			//			}
			//		}
			//		if(ids == "")
			//		{

			//			window.location.href="{:U('groupList')}";
			//		}
			//		else if(data.status == 0)
			//		{
				//		alert(data.message);
				//	}
				//}); -->
	
		//批量删除数据
		$("#delete").click(function(){
			var aa = $("input[name='check']");
			var ids = new Array();
			var j=0;
			for (var i = 0; i < aa.length; i++) {
				if (aa[i].checked) {
					ids[j] = aa[i].value;
					j++;
				}
			}
			if(ids == "")
			{
				alert("请选择要删除的项");
			}
			else
			{
			    if(confirm('确定要删除这些吗？'))
			{
				//check(ids,"del","");
				$.post("{:U('doDels')}",{id:ids},function(data){
				if(data.status == 1)
				{
					alert(data.message);
					window.location.href="{:U('groupList')}";
				}
				else if(data.status == 0)
				{
					alert(data.message);
				}
			});
			}
			}

		});
		function doExamine(id,type){
			$.post("{:U('toExamine')}",{id:id,type:type},function(data){
				if(data.status == 1)
				{
					alert(data.message);
					window.location.href="{:U('groupList')}";
				}
				else if(data.status == 0)
				{
					alert(data.message);
				}
			});
		}
		$("#examine").click(function(){
			var aa = $("input[name='check']");
			var ids = new Array();
			var j=0;
			for (var i = 0; i < aa.length; i++) {
				if (aa[i].checked) {
					ids[j] = aa[i].value;
					j++;
				}
			}
			if(ids == "")
			{
				alert("请选择要审核的项");
			}
			else
			{
				doExamine(ids,'del');
			}

		});

		function check(id,type,$_this){
			$.post("{:U('checkGroup')}",{id:id},function(data){
				if(data.status == 1)
				{
					alert("该团正在进行中，不能进行操作");
				}
				else if(data.status == 0)
				{
					if(type=="del"){
						deletes(id);
						return;
					}else{
					if(type=="complete"){
						iscomplete(id);
						return;
					}
					    doExamine(ids);
					}
					}
			 });
		  }	
		
   function check_edit(id,type,$_this){
   	 
      $.post("{:U('checkGroup')}",{id:id},function(data){
						   if(data.status == 1)
						   {   
						   	debugger;
						   	  //console.log(data);
							   //正在团购中的，只能编辑商品图片
							   var edit = 1;
							   var url = $($_this).attr("url");
							   var str_url = url.replace("0.html","1.html");
							   window.location.href=str_url;


						   }
						   else if(data.status == 0)
						   {
						        if(type=="del"){
						        	deletes(id);
						        	return;
						        }
								
							    if(type=="complete"){
							    	iscomplete(id);
							    	return;
							    }

								
								window.location.href=$($_this).attr("url");
						   }
					 });
   }
			  function goSearch(){
			      $("#SearchFrom").submit();
			  }
			 function inputGoToPages(listrows){
			    var page=$(listrows).val();
				$("#listrows").val(page);
				$("#SearchFrom").submit();
			 }
			 
			 function selectGoToPages(page){
			    var _page=$(page).val();
			    $("#_page").val(_page);
				$("#SearchFrom").submit();
			 }
</script>
</block>